<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>absolutePan</title>
  <style>
    .btn-x {
      margin-bottom: 10px;
    }
    #canvasBox {
      border: 1px solid #ccc;
    }
  </style>
</head>
<body>
  <div class="btn-x">
    <button onclick="absolutePan()">平移画布</button>
  </div>
  <canvas id="canvasBox" width="600" height="600"></canvas>

<script src="../../script/fabric.js"></script>
<script>

  let canvas = null
  window.onload = function() {
    // 使用 元素id 创建画布，此时可以在画布上框选
    canvas = new fabric.Canvas('canvasBox')

    fabric.Image.fromURL('../../images/bg.jpg', img => {
      canvas.setBackgroundImage(img)
      canvas.renderAll()
    })
  }

  function absolutePan() {
    canvas.absolutePan(new fabric.Point(20, 100))
  }

</script>
</body>
</html>